package com.kun.index.controller;


import com.kun.common.ResultDto;
import com.kun.index.entity.CollectUserBlog;
import com.kun.index.service.impl.CollectUserBlogServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 用户收藏博客表 前端控制器
 * </p>
 *
 * @author kunkun
 * @since 2024-03-26
 */
@RestController
@RequestMapping("/index/collect-user-blog")
public class CollectUserBlogController {

    @Autowired
    private CollectUserBlogServiceImpl collectUserBlogService;

    @PostMapping("/addCollection")
    @ApiOperation("收藏")
    public ResultDto addCollection(@RequestBody CollectUserBlog collectUserBlog) {

        Integer num = collectUserBlogService.addCollection(collectUserBlog);
        if (num!=null){
            return ResultDto.success("收藏成功");
        }else{
            return ResultDto.fail("收藏失败");
        }
    }

    @PostMapping("/deleteCollection")
    @ApiOperation("取消收藏")
    public ResultDto deleteCollection(@RequestBody CollectUserBlog collectUserBlog) {

        Integer num = collectUserBlogService.deleteCollection(collectUserBlog);
        if (num!=null){
            return ResultDto.success("取消收藏成功");
        }else{
            return ResultDto.fail("取消收藏失败");
        }
    }

    @PostMapping("/checkCollectionStatus")
    @ApiOperation("查询收藏状态")
    public ResultDto checkCollectionStatus(@RequestBody CollectUserBlog collectUserBlog) {

        Integer num = collectUserBlogService.checkCollectionStatus(collectUserBlog);
        if (num!=null && num>0){
            return ResultDto.success("已经收藏");
        }else{
            return ResultDto.fail("未收藏");
        }
    }
    
}

